package com.dcm.seacher.lucene;

import java.io.File;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;


public class CreateIndex {

	public static boolean create=true;
	
	String indexPath = "e:/lucene01";

	Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
	
	//Analyzer analyzer = new MMAnalyzer();
	public void createIndex(Document doc) throws Exception {
		Directory dir = FSDirectory.open(new File(indexPath));
		IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(Version.LUCENE_36, analyzer));
		if(create)
		{
			create=false;
		}
		indexWriter.addDocument(doc);
		indexWriter.close();
	}
}
